package com.uinnova.product.eam.init.schedule;

import com.binary.framework.bean.annotation.Comment;
import com.uinnova.product.eam.init.schedule.job.AutoArchiveJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Comment("自动归档系统文件夹任务配置")
@Configuration
public class AutoArchiveConfiguration {

    @Value("${category.auto.archive.cron:0 0 0 1 1 ? *}")
    private String autoArchiveCron;

    @Bean
    public JobDetail autoArchiveJob() {
        return JobBuilder.newJob(AutoArchiveJob.class).withIdentity("AutoArchiveJob").storeDurably().build();
    }

    @Bean
    public Trigger autoArchiveJobTrigger(JobDetail autoArchiveJob) {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(autoArchiveCron);
        return TriggerBuilder.newTrigger().forJob(autoArchiveJob)
                .withIdentity("AutoArchiveJob").withSchedule(scheduleBuilder).build();
    }

}